#include <math.h>
#include <stdio.h>

void printfixedsin(short n1,short n3,short flag)
{
    char s[15];
    int i,k,n,n2;
    int jj=0;
    double f1,f2,f3;
    int m2[8];

    unsigned int Ampltitude;
    Ampltitude=1<<(n1-1);
    n=1<<n3;
    n2=n-n/4;//N_WAVE-N_WAVE/4 这样修改后可以适应n>N_WAVE情况
    FILE *fp;
    sprintf(&s,"%d_%d_%u%s",n3,n1/8,sizeof(myint2),".c");
    fp = fopen(&s,"w+");
    fprintf(fp,"const myint2 Sinewave[N_WAVE-N_WAVE/4] = {\n");

    //flag==1,2,3,4代表打印0~pi/2*flag周期的值
    while(jj<n2)
    {
        for(k=0; k<8; k++)
        {
            if(jj>=n2)
                break;
            f3=(double)jj / n *flag;
            f1=PI /2.0 ;
            f2=sin(f1*f3);
            m2[k]=f2 * (double)Ampltitude;
            //fprintf(fp,"%d %d %g %g %g",jj,n,f3,f1,f2);
            //fprintf(fp,(sizeof(m2[k])<=2?"%d":"%ld"),m2[k]);
            fprintf(fp,"%d,",m2[k]);
            jj++;
        }
        fprintf(fp, "\n");
    }
    fprintf(fp, "}\n");
    fclose(fp);
    fp=NULL;

}
